﻿using JuCheap.Core.Infrastructure.Extentions;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;

namespace JuCheap.Core.Model.Message
{
    /// <summary>
    /// 站内信创建模型
    /// </summary>
    public class MessageCreateRequestDto
    {
        /// <summary>
        /// 标题
        /// </summary>
        [Display(Name = "标题")]
        [Required(ErrorMessage = "{0}不能为空")]
        [MaxLength(200, ErrorMessage = "{0}长度不能超过{1}个字符")]
        public string Title { get; set; }

        /// <summary>
        /// 内容
        /// </summary>
        [Display(Name = "内容")]
        [Required(ErrorMessage = "{0}不能为空")]
        [MaxLength(2000, ErrorMessage = "{0}长度不能超过{1}个字符")]
        public string Contents { get; set; }

        /// <summary>
        /// 接收人Id集合
        /// </summary>
        [Display(Name = "接收人")]
        [Required(ErrorMessage = "{0}不能为空")]
        public IList<string> ReceiverIds { get; set; }

        /// <summary>
        /// 获取发送类型
        /// </summary>
        /// <returns></returns>
        public MessageType GetSendType()
        {
            
            if(ReceiverIds.AnyOne() && ReceiverIds.Any(x => x.IsEqual("-1")))
            {
                return MessageType.All;
            }
            return MessageType.Users;
        }
    }
}
